﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;

namespace NewsReader
{
    public partial class FeedList : UserControl
    {
        public FeedList()
        {
            // Required to initialize variables
            InitializeComponent();
        }
        // Handle selection changed on ListBox
        private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox MainListBox = sender as ListBox;
            // If selected index is -1 (no selection) do nothing
            if (MainListBox.SelectedIndex == -1)
                return;

            Microsoft.Phone.Tasks.WebBrowserTask tsk = new Microsoft.Phone.Tasks.WebBrowserTask();
            tsk.URL = ((MainListBox.ItemsSource as IList)[MainListBox.SelectedIndex] as RssItem).Url;
            tsk.Show();

            // Reset selected index to -1 (no selection)
            MainListBox.SelectedIndex = -1;
        }
    }
}